package com.theo.mapper;

import com.theo.entity.OrderInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 方涛
 * @since 2021-03-31
 */
@Repository
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {

    int saveOrderInfo(OrderInfo orderInfo);

    int deleteOrderInfo(Integer id);

    int updateOrderInfo(Integer id);

    @Select("SELECT temp2.`id`,temp2.`order_code`,u.`user_name`,temp2.`hospital_name`,temp2.`user_id`,temp2.`article_id`,temp2.`mask_name` `article_name`,temp2.`order_price`,temp2.`create_time`\n" +
            "FROM `user_info` u INNER JOIN\n" +
            "(\n" +
            "SELECT h.`hospital_name`,temp.`user_id`,temp.`article_id`,temp.`mask_name`,temp.`order_price`,temp.`create_time`,temp.`order_code`,temp.`id`\n" +
            "FROM `hospital_info` h INNER JOIN\n" +
            "(\n" +
            "SELECT o.`id`,o.`order_code`,o.`article_id`,m.`mask_name`,o.`hospital_id`,o.`user_id`,o.`order_price`,o.`create_time`\n" +
            "FROM `order_info` o INNER JOIN `mask_info` m\n" +
            "ON o.`article_id` = m.`mask_id`\n" +
            ")temp ON h.`hospital_id` = temp.`hospital_id`\n" +
            ")temp2 ON u.`user_id` = temp2.`user_id`")
    List<OrderInfo> queryAllOrderInfo();

    OrderInfo queryOrderInfoById(Integer id);
}
